package com.user.controller;


import cn.hutool.log.Log;
import com.user.common.R;
import com.user.config.AliyunOSSProp;
import com.user.config.AliyunOSSUtils;
import com.user.service.IFeedbackService;
import com.usian.model.shop.Feedback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * <p>
 * 意见反馈 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-18
 */
@RestController
@RequestMapping("/feedback")
@Slf4j
public class FeedbackController {
    @Autowired
    private IFeedbackService feedbackService;
    @Autowired
    private AliyunOSSProp aliyunOSSProp;
    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;
    @RequestMapping("/findList")
    public R findList(){
        List<Feedback> list = feedbackService.findList();
        return R.success(list);
    }

    @RequestMapping("/add")
    public R add(@RequestBody Feedback feedback) {
        feedback.setStatus(1);
        feedbackService.save(feedback);
        return R.success("添加成功");
    }

    @RequestMapping("/fileUpload")
    public String upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        InputStream inputStream = file.getInputStream();
        log.info(inputStream+"================");
        String s=aliyunOSSUtils.putObject(inputStream,originalFilename);
        return s;
    }


    @RequestMapping("/status")
    public R status( Integer id){
        feedbackService.status(id);
        return R.success("修改成功");
    }

    @RequestMapping("/find")
    public R find(Integer id){
        Feedback feedback = feedbackService.find(id);
        return R.success(feedback);
    }

}
